package project;

import java.util.Arrays;
import java.util.List;

public class Validator {

	// TODO complete this class using your project code
	// you must implement the no-arg constructor and the check method
	
	// you may add extra fields and methods to this class
	// but the ProvidedTests code will only call the specified methods
	
	public Validator() {
	}

	/**
	 * Check the validity of a given sequence of moves.
	 * The sequence is valid if and only if each (space separated)
	 * move in the list is valid,
	 * starting from the initial position of the game.
	 * When the game has been won, no further moves are valid.
	 * @param moves a list of successive moves
	 * @return validity of the list of moves
	 */
	public boolean check(String moves) {
		String[] movesArray = moves.split("/ +/");
		return check(Arrays.asList(movesArray));
	}
	
	public boolean check(List<String> moves) {
		GameState state = new GameState();
		for (String string : moves) {
			Move move = Move.newMove(string, state.currPlayer);
			if (Validity.isValid(move, state)) {
				state.applyMove(move);
			} else {
				return false;
			}
		}
		return true;
	}

}